//
//  LaberTableViewCell.m
//  Miss
//
//  Created by Alan on 15/1/28.
//  Copyright (c) 2015年 Alan. All rights reserved.
//

#import "LaberTableViewCell.h"

@interface LaberTableViewCell()
- (void)setMainLaber;
@end

@implementation LaberTableViewCell
- (void)dealloc
{
    [_laberPic release];
    [_laberPic1 release];
    [_mainLaber release];
    [_dateLaber_date release];
    [_dateLaber_month release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setMainLaber];
    }
    return self;
}
- (void)setMainLaber
{
    //背景颜色
    self.laberPic = [[UIImageView alloc]init];
    [_laberPic setImage:[UIImage imageNamed:@"laberPic.jpg"]];
    [self.contentView addSubview: self.laberPic];
    [_laberPic release];
    //背景颜色框
    self.laberPic1 = [[UILabel alloc]init];
    self.laberPic1.backgroundColor = [UIColor colorWithRed:55/255.0f green:196/255.0f blue:242/255.0f alpha:1];
    self.laberPic1.layer.cornerRadius = 3;
    self.laberPic1.layer.masksToBounds = YES;
    [self.contentView addSubview:self.laberPic1];
    [_laberPic release];
    //文字
    self.mainLaber = [[UILabel alloc]init];
    self.mainLaber.textColor = [UIColor whiteColor];
    self.mainLaber.backgroundColor = [UIColor colorWithRed:55/255.0f green:196/255.0f blue:242/255.0f alpha:1];
    self.mainLaber.font = [UIFont systemFontOfSize:12];
    self.mainLaber.text = @"郝军郝军郝军郝军郝军郝军郝军郝军郝军郝军郝军郝军郝军郝军郝军郝军郝军郝军郝军郝军郝军郝军郝军郝军郝军郝军";
    self.mainLaber.numberOfLines = 3;
    self.mainLaber.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:self.mainLaber];
    [_mainLaber release];
    //日期
    self.dateLaber_date = [[UILabel alloc]init];
    self.dateLaber_month = [[UILabel alloc]init];
    //定义(设置当前星期)
    NSDate *date = [NSDate date];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *comps;
    //获得年月日
    comps = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay) fromDate:date];
    NSInteger year = [comps year];
    NSInteger month = [comps month];
    NSInteger day = [comps day];
    NSLog(@"year:%ld month: %ld, day: %ld", year, month, day);
    //日的设置
    self.dateLaber_date.text = [NSString stringWithFormat:@"%ld",day];
    self.dateLaber_date.font = [UIFont systemFontOfSize:40];
    self.dateLaber_date.textColor = [UIColor colorWithRed:55/255.0f green:196/255.0f blue:242/255.0f alpha:1];
    [self.contentView addSubview: self.dateLaber_date];
    [_dateLaber_date release];
    //年月的设置
    NSArray *arr = [NSArray arrayWithObjects:@"Jan", @"Feb", @"Mar", @"Apr", @"May", @"Jun" ,@"Jul", @"Aug",@"September" ,@"Oct", @"Nov",@"Dec", nil];
    NSString *monthstr = [arr objectAtIndex:month - 1];
        self.dateLaber_month.text = [NSString stringWithFormat:@"%@,%ld",monthstr,year];
    self.dateLaber_month.font = [UIFont systemFontOfSize:12];
    self.dateLaber_month.textColor = [UIColor grayColor];
    [self.contentView addSubview: self.dateLaber_month];
    [_dateLaber_month release];
    
    
}
- (void)layoutSubviews
{
    self.laberPic.frame = CGRectMake(60, 20, 295, 20);
    self.laberPic1.frame = CGRectMake(65, 25, 290, 60);
    self.mainLaber.frame = CGRectMake(70, 25, 280, 50);
    self.dateLaber_date.frame = CGRectMake(10, 14, 50, 50);
    self.dateLaber_month.frame = CGRectMake(10, 50, 60, 30);
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
